package com.ruoyi.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.mapper.AssetMapper;
import com.ruoyi.domain.Asset;
import com.ruoyi.service.AssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class AssetServiceImpl implements AssetService {
    @Autowired
    private AssetMapper assetMapper;

    //添加
    @Override
    public void addAsset(Asset asset) {
        assetMapper.insertAsset(asset);
    }

    //主键查询
    @Override
    public Asset selectAssetByAssetNo(String assetNo) {
        return assetMapper.selectByAssetNo(assetNo);
    }
    //更新
    @Override
    public void updateAsset(Asset asset) {
        assetMapper.updateAsset(asset);
    }

    //删除
    @Override
    public void deleteAssetByAssetNo(String assetNo) {
        assetMapper.deleteAssetByAssetNo(assetNo);
    }

    //模糊条件查询
    @Override
    public Map<String, Object> selectAsset(int page, int limit, String assetNo, String assetName, String responsibilityDepartmentName, String period) {
        List<Asset> assets = assetMapper.selectAsset(assetNo,assetName,responsibilityDepartmentName,period);
        PageHelper.startPage(page,limit);
        Map<String, Object> result = new HashMap<>();
        result.put("total", assets.size());
        result.put("data", assetMapper.selectAsset(assetNo,assetName,responsibilityDepartmentName,period));
        return result;
    }

    //全查
    @Override
    public Map<String, Object> selectAllAsset(int page, int limit) {
        List<Asset> assets = assetMapper.selectAllAsset();
        PageHelper.startPage(page,limit);
        Map<String, Object> result = new HashMap<>();
        result.put("total", assets.size());
        result.put("data", assetMapper.selectAllAsset());
        return result;
    }
}
